$(function () {
    $("#page").load("/html/page.html");
    selectGroup();
});

function selectGroup() {
    let result = myAjax('/group/selectAll', 'post', {});
    let html = " ";
    for (let i = 0; i < result.list.length; i++) {
        html += ' <option value="' + result.list[i].id + '">' + result.list[i].name + '</option>';
    }
    $("#group").html(html);
}

function searchAll() {
    let data = {
        groupName: $("#group").find("option:selected").text(),
        userName: $("#userName").val(),
        isLeader: $("#isLeader").find("option:selected").val(),
        startAddTime: $("#startAddTime").val(),
        endAddTime: $("#endAddTime").val(),
        pageSize: $.trim($("#pageSize").val()),
        pageNum: $.trim($("#pageNum").val()),
    }
    $("#look-group-name").html(data.groupName);
    let result = myAjax('/member/groupMemberList', 'post', data);
    show(result.list);
    $("#pageCount").html(result.number);
}
function show(data) {
    let html = "";
    for (let i = 0; i < data.length; i++) {
        html += '   <tr> ' +
            '  <td><input type="checkbox" name="isCheck" value="'+data[i].id+'">' + data[i].id + '</td>\n' +
            '        <td>' + data[i].groupId + '</td>\n' +
            '        <td>' + data[i].groupName + '</td>\n' +
            '        <td>' + data[i].userId + '</td>\n' +
            '        <td>' + data[i].userName + '</td>\n' +
            '        <td>' + data[i].addTime + '</td>\n' +
            '        <td>' + data[i].isLeader + '</td>\n' +
            '        <td><input type="button" style="width: 60px;border-radius: 5px;' +
            'background-color: #5FB878" value="查看" onclick="lookMember('+ data[i].id +',`'+data[i].groupName+'`)"></td>' +
            '    </tr>';
        sessionStorage.setItem("group-id-info",data[i].groupId);
    }
    $("#findAll").html(html);
}
//点击修改按钮进行页面弹出，传递两个参数，一个小组id一个小组名字，然后动态赋值给弹出页面，后面添加成员要用到。
layui.use('layer');
function lookMember(id,name) {
    sessionStorage.setItem("group-member-user-id",id);
    //弹出一个页面层
    let html = "<span id='group-name-edit'>"+name+"</span>"
    layer.open({
        type: 2,
        anim:3,
        title:'查看'+html+'',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/groupMemberEdit.html','no'],
    })
}
function addOrClear() {
    let id = sessionStorage.getItem("group-id-info");
    console.log( $("#look-group-name").text());
    let groupName= $("#look-group-name").text();
    if (groupName!="全部"){
    sessionStorage.setItem("add-new-group-member", $("#look-group-name").text())
    sessionStorage.setItem("id-add-member",id);
    let name = $("#look-group-name").text();
    layer.open({
        type: 2,
        anim:3,
        title:''+name+'分配成员',
        area: ['600px', '500px'],
        shadeClose: true, //点击遮罩关闭
        content: ['/html/addMember.html','no'],
    })
    }else {
        layer.msg("请先选择要操作的小组！！")
    }
}